import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { CreateUpdateRfidDto, RfidDto } from './models';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-rfid-modal',
  standalone: true,
  imports: [ReactiveFormsModule, CommonModule],
  templateUrl: './rfid-modal.component.html',
})
export class RfidModalComponent implements OnInit {
  form: FormGroup;
  isEdit = false;
  
  // 添加类型选项数组
  typeOptions: string[] = [
    '商品',
    '货架',
    '托盘',
    '包装',
    '车辆',
    '人员',
    '其他'
  ];

  constructor(
    private fb: FormBuilder,
    public activeModal: NgbActiveModal
  ) {
    this.form = this.fb.group({
      rfid1: ['', Validators.required],
      type: ['', Validators.required],
      businessContent: [''],
      rfid2: [''],
      rfid3: [''],
    });
  }

  ngOnInit(): void {}

  setRfid(rfid: RfidDto) {
    this.isEdit = true;
    this.form.patchValue({
      rfid1: rfid.rfid1,
      type: rfid.type,
      businessContent: rfid.businessContent,
      rfid2: rfid.rfid2,
      rfid3: rfid.rfid3,
    });
  }

  save() {
    if (this.form.invalid) {
      return;
    }
    this.activeModal.close(this.form.value);
  }
} 